import {API_COMMENTS_CHILDREN, API_COMMENTS_COUNT, API_COMMENTS_INSET, API_COMMENTS_LIST} from "@/constant/api";
import {Page} from "@/entity/page";
import {Comments} from "@/entity/comments";

export default new class comments {
    /**
     * 获取评论列表
     */
    getList = (page?: Page, comments?: Comments) => {
        return useUtils().HttpUtils.get(API_COMMENTS_LIST, {
            ...comments,
            ...page,
        });
    }

    /**
     * 获取子评论列表
     */
    getChildrenList = (id?: string, page?: Page) => {
        return useUtils().HttpUtils.get(API_COMMENTS_CHILDREN + "/" + id, {...page});
    }

    /**
     * 用户评论
     */
    setComments = (siteId: string, commentsText: string, repliedUsername?: string, commentsId?: string) => {
        return useUtils().HttpUtils.post(API_COMMENTS_INSET, {siteId, commentsText, repliedUsername, commentsId});
    }

    /**
     * 用户删除评论
     */
    delComments = (id: string) => {
        return useUtils().HttpUtils.delete(API_COMMENTS_LIST + "/" + id);
    }

    /**
     * 获取评论数量
     */
    getCount = () => {
        return useUtils().HttpUtils.get(API_COMMENTS_COUNT);
    }
};